package com.thomasgustavo.meugood;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;

public class Login {
	private static Login mySelf;
	
	private Map<String, HttpClient> httpclient;

	private Login(){
		httpclient = new HashMap<String, HttpClient>();
	}
	
	public static void destroy(){
		mySelf = null;
	}
	
	public static Login getInstance(){
		if( mySelf == null ){
			mySelf = new Login();
		}
		return mySelf;
	}

	public void setHttpclient(String nroCartao, String response, HttpClient httpclient) throws Exception {
		if( isSuccessLogin(response)){
			this.httpclient.put(nroCartao, httpclient);
			return;
		}
		throw new Exception("Ocorreu um erro ao efetuar login.");
	}
	
	private boolean isSuccessLogin(String response){
		if( response.contains("ambiente	= 'Producao'")){
			return true;
		}
		return false;
	}

	public boolean isLogged( String nroCartao ) {
		return httpclient.containsKey(nroCartao);
	}

	public HttpClient getHttpclient(String nroCartao) {
		return httpclient.get(nroCartao);
	}
}
